package com.rw.coco.handler.message.reply.handler.validate;

import com.rw.coco.handler.message.event.CocoMessageEvent;
import com.rw.coco.handler.message.reply.ReplyFilter;
import com.rw.coco.util.config.CocoConfig;
import com.rw.coco.util.config.CocoOption;

/**
 * 消息长度拦截器
 */
public class MessageLengthFilter extends ReplyFilter {
    private final int maxLength;

    public MessageLengthFilter(CocoConfig cocoConfig) {
        CocoOption cocoOption = cocoConfig.getCocoOption();
        this.maxLength = cocoOption.optionProp.getInt(CocoOption.MSG_MAX_LENGTH);
    }

    @Override
    public boolean trigger(CocoMessageEvent cocoMessageEvent) {
        return cocoMessageEvent.getMessage().length() > maxLength;
    }
}

